import { fileURLToPath, URL } from "url";
import { resolve } from "path";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

const pathResolve = (dir) => {
  return resolve(__dirname, ".", dir);
};

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // createSvgIconsPlugin({
    //   iconDirs: [path.resolve(process.cwd(), "src/icons/svg")],
    //   symbolId: "[name]",
    // }),
  ],
  //  生产环境
  build: {
    //指定输出路径
    assetsDir: "./",
    // 指定输出文件路径
    outDir: "dist",
    // 代码压缩配置
    terserOptions: {
      // 生产环境移除console
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
  server: {
    open: true,
    port: 7001,
    host: "localhost",
    // 配置代理
    proxy: {
      // 跨域代理
      "/admin": {
        target: "https://yuanliren.youli.tech",
        changeOrigin: true, // 默认情况下，代理时会保留主机头的来源，可以将 changeOrigin 设置为 true 以覆盖此行为
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      assets: pathResolve("./src/assets"),
    },
  },
});
